'use strict';

/**
 * @name 审核操作
 * @description params.data.verified为审核是否通过, params.data.module为审核的模块, params.data.state为修改之后的状态
 * @author ZYF
 */

angular.module('metalabOperationApp').controller('VerifiedModelCtrl', ['$rootScope', '$stateParams', '$state', 'params', '$scope', '$uibModalInstance', 'MetaResources', 'MetaRemind', function($rootScope, $stateParams, $state, params, $scope, $uibModalInstance, MetaResources, MetaRemind) {
    $scope.sure = function() {
      MetaResources[params.data.module].save({
        'id': $stateParams.id
      }, {
        'state': params.data.state,
        'verified': params.data.state==='审核中' ? null : params.data.verified,
        'verifierId': params.data.state==='审核中' ? null : '_self'
      }, function() {
          if (params.data.state==='审核中') {
            MetaRemind.success("恭喜", "进入审核状态");
          } else if (params.data.state==='不通过') {
            MetaRemind.success("恭喜", "操作成功");
          } else {
            MetaRemind.success("恭喜", "审核通过");
          }
          $uibModalInstance.dismiss('cancel');
          $state.reload();
      },
      function(error) {
          MetaRemind.serverError(error);
          $uibModalInstance.dismiss('cancel');
      });
    };
    $scope.cancel = function() {
        $uibModalInstance.dismiss('cancel');
    };
}]);
